package com.leetcode;

import java.util.*;

public class MergeRecord {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        int nums = sc.nextInt();
        Map<Integer, Integer> map = new HashMap<>();

        for (int i = 0; i < nums; i++) {
            int index = sc.nextInt(), value = sc.nextInt();
            int v = map.getOrDefault(index, 0);
            map.put(index, v + value);
        }

        map.entrySet().stream()
                .sorted(Comparator.comparingInt(Map.Entry::getKey))
                .forEach(entry -> {
                    System.out.println(entry.getKey() + " " + entry.getValue());
                });

    }
}
